//
//  DYYuyueTimeSubCell.swift
//  SheYangBigData
//
//  Created by 宋海胜 on 2021/1/5.
//  Copyright © 2021 叁拾叁. All rights reserved.
//

import UIKit
import YYText
import SwiftDate

class DYYuyueTimeSubCell: SYBaseCollectionViewCell {
    
    let titles:[String] = ["今天", "明天", "后天"]
    let timeLb: UILabel = {
        let v:UILabel = UILabel()
        v.textColor = UIColor(hex: 0x1E1E1E)
        v.font = 14.autoFontSize()
        v.text = "今天 12-07"
//        v.textAlignment = .center
        return v
    }()
    
    let priceLb: YYLabel = {
        let v:YYLabel = YYLabel()
        return v
    }()
    
    let pic: UIImageView = {
        let v: UIImageView = UIImageView()
        v.image = UIImage(named: "kuang")
//        v.layer.cornerRadius = 6
        return v
    }()
    

    public func configureView(_ model: DYJQYuyueTimeModel) {
        
        let now = Date()
        let nowStr = now.sy_toString(format: "MM-dd")
                let tomorrow = now + 1.days
                let tomorrowStr = tomorrow.sy_toString(format: "MM-dd")
        let houtian = now + 2.days
        let houtianStr = houtian.sy_toString(format: "MM-dd")
        
        switch model.str {
        case nowStr:
            timeLb.text = "今天  \(model.str ?? "")"
        case tomorrowStr:
            timeLb.text = "明天  \(model.str ?? "")"
        case houtianStr:
            timeLb.text = "后天  \(model.str ?? "")"
        default:
            timeLb.text = "\(model.str ?? "")"
        }
        
        let showStr = "¥\(model.money ?? "")"
        let attString = NSMutableAttributedString(string: showStr)
        attString.yy_setColor(UIColor(hex: 0xF55035), range: NSRange(location: 0, length: 1))
        attString.yy_setFont(10.autoFontSize(), range: NSRange(location: 0, length: 1))
        attString.yy_setColor(UIColor(hex: 0xF55035), range: NSRange(location: 1, length: showStr.count-1))
        attString.yy_setFont(14.autoFontSize(), range: NSRange(location: 1, length: showStr.count-1))
        priceLb.attributedText = attString
        
//        priceLb.attributedText = self.setPriceLb(model.money)
        
    }
    
    override func initViews() {
        
        addSubview(pic)
        addSubview(timeLb)
        addSubview(priceLb)
        timeLb.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(13.0.autoWidth())
            make.left.equalToSuperview().offset(3.0.autoWidth())
            make.right.equalToSuperview()
            make.height.equalTo(13.0.autoWidth())
            
        }
        priceLb.snp.makeConstraints { (make) in
            make.top.equalTo(timeLb.snp.bottom).offset(9.5.autoWidth())
            make.left.equalToSuperview().offset(9.0.autoWidth())
            make.height.equalTo(11.5.autoWidth())
            make.bottom.equalToSuperview().offset(-11.0.autoWidth())
        }
        pic.snp.makeConstraints { (make) in
            make.top.bottom.equalToSuperview()
            make.left.equalToSuperview()
            make.right.equalToSuperview()
        }
    }
}

